<template>
  <div class="ExtensionDetail">
    <div><h4>推广员详情</h4></div>
    <div v-if="info" class="cus-header-content">
      <div class="left">
        <div class="elea">
          <div>
            <img
              :src="require('@/assets/images/avator.png')"
              alt=""
            >
          </div>
          <span>{{ info.nickname }}</span>
        </div>
        <p>
          <span>手机号码:</span><span>{{ info.mobile }}</span>
        </p>
        <p>
          <span>推广方案:</span><span>{{ info.customTemplate }}</span>
        </p>
        <p>
          <span>备注:</span><span>{{ info.remark }}</span>
        </p>
      </div>
      <div class="right">
        <div>
          <p>积累订单</p>
          <p>
            <span>{{ info.orderCount }}</span>
          </p>
        </div>
        <div>
          <p>累计销售额</p>
          <p>
            <span>￥{{ parseFloat(info.orderPriceCount).toFixed(2) }}</span>
          </p>
        </div>
        <div>
          <p>累计客户</p>
          <p>
            <span>{{ info.customerCount }}</span><el-button
              size="mini"
              circle
              icon="el-icon-arrow-right"
              type="primary"
              plain
              @click="
                $router.push({
                  name: 'TableDetail',
                  params: { id: promoterId, state: true }
                })
              "
            />
          </p>
        </div>
        <div>
          <p>佣金</p>
          <p>
            <span>￥{{ parseFloat(info.commissionCount).toFixed(2) }}</span>
          </p>
        </div>
        <div>
          <p>已结算</p>
          <p>
            <span>￥{{ parseFloat(info.isSettlementPrice).toFixed(2) }}</span>
          </p>
        </div>
        <div>
          <p>待结算</p>
          <p>
            <span>￥{{ parseFloat(info.unSettlementPrice).toFixed(2) }}</span>
          </p>
        </div>
        <div>
          <p>可提现金额</p>
          <p>
            <span>￥{{ parseFloat(info.unWithdrawalPrice).toFixed(2) }}</span>
          </p>
        </div>
        <div>
          <p>已提现金额</p>
          <p>
            <span>￥{{ parseFloat(info.withdrawalPrice).toFixed(2) }}</span><el-button
              size="mini"
              circle
              icon="el-icon-arrow-right"
              type="primary"
              plain
              @click="
                $router.push({
                  name: 'TableDetail',
                  params: { id: userId, state: false }
                })
              "
            />
          </p>
        </div>
      </div>
    </div>
    <div class="ele-tabs-table">
      <div class="key-search">
        <div />
        <div class="right">
          <el-input
            v-model="keySearch"
            placeholder="输入手机号，订单号搜索"
            prefix-icon="el-icon-search"
            clearable
          />
          <el-button type="primary" @click="handelSearch"> 确认 </el-button>
        </div>
      </div>
      <el-tabs v-model="activeModel" @tab-click="handelTabs">
        <el-tab-pane name="-1" label="全部">
          <div v-if="activeModel == '-1'">
            <tableCustom :promoter-id="userId" :key-search="keyValue.keySearch" />
          </div>
        </el-tab-pane>
        <el-tab-pane
          name="0"
          label="待结算"
        >
          <div v-if="activeModel == '0'">
            <tableCustom type="0" :promoter-id="userId" :key-search="keyValue.keySearch" />
          </div>
        </el-tab-pane>
        <el-tab-pane
          name="1"
          label="已结算"
        >
          <div v-if="activeModel == '1'">
            <tableCustom type="1" :promoter-id="userId" :key-search="keyValue.keySearch" />
          </div>
        </el-tab-pane>
      </el-tabs>
    </div>
  </div>
</template>

<script>
/** 推广员详情 */
import tableCustom from './../component/table.vue'
import { ExtensionPromoterDetail } from '@/api/customAPI/shop/ExtensionManagement'
export default {
  name: 'ExtensionDetail',
  components: {
    tableCustom
  },
  data() {
    return {
      keySearch: '',
      activeModel: '-1',
      info: null,
      promoterId: null,
      userId: null,
      keyValue: {
        type: '',
        keySearch: ''
      }
    }
  },
  created() {
    const param = this.$dd(this.$route.query.p)
    if (!param || !param.promoterId) {
      this.$router.push({ name: 'ExtensionManagement' })
      this.$message.warning('请先选择推广员')
    } else {
      console.log(param)
      this.promoterId = param.promoterId
      this.userId = param.userId
      this.Init()
    }
  },
  methods: {
    handelSearch() {
      this.keyValue.keySearch = this.keySearch
      this.$forceUpdate()
    },
    /** 初始化 */
    Init() {
      const vm = this
      ExtensionPromoterDetail({
        shopId: localStorage.getItem('shopId'),
        promoterId: vm.promoterId
      })
        .then(result => {
          vm.info = result.data.data
          console.log(result)
        })
        .catch(err => {
          console.log(err)
        })
    },
    handelTabs(e) {
      this.keySearch = ''
      this.keyValue.keySearch = ''
      this.keyValue.type = e.name
      this.$forceUpdate()
    }
  }
}
</script>

<style lang="scss" scoped>
.ExtensionDetail {
  padding: 50px 100px;
  .cus-header-content {
    display: flex;
    .left,
    .right {
      padding: 20px;
      border-radius: 5px;
      background: #f3f3f3;
    }
    .left {
      width: 980px;
      display: flex;
      flex-direction: column;
      justify-content: space-around;
      .elea {
        display: flex;
        div {
          width: 60px;
          height: 60px;
          border-radius: 5px;
          overflow: hidden;
          img {
            width: 100%;
            height: 100%;
            object-fit: cover;
          }
        }
        span {
          padding-left: 30px;
        }
      }
      p {
        span {
          display: inline-block;
          width: 100px;
          font-size: 0.95rem;
        }
      }
    }
    .right {
      flex-grow: 1;
      margin-left: 30px;
      display: flex;
      flex-wrap: wrap;
      div {
        background: white;
        border-radius: 5px;
        width: 180px;
        padding: 0px 15px;
        margin-right: 20px;
        margin-top: 20px;
        p:first-child {
          font-weight: bold;
        }
        p:last-child {
          display: flex;
          align-items: center;
          justify-content: space-between;
        }
      }
    }
  }
  .ele-tabs-table {
    margin-top: 40px;
    .key-search {
      z-index: 1000;
      position: relative;
      .right {
        position: absolute;
        right: 0;
        .el-input {
          width: 240px;
        }
      }
    }
  }
}
</style>
yle>
